// #ifdef APP-PLUS
const BindingX = uni.requireNativePlugin('bindingx');
const animation = weex.requireModule('animation');
const modal = weex.requireModule('modal');
// #endif

export function  transition(el, options, duration, delay = 0,needLayout=false) {
				return new Promise((resolve) => {
					animation.transition(el, {
						duration,
						delay,
						timingFunction: 'ease',
						needLayout: needLayout,
						...options,
					}, resolve)
				})
			};
			
export function  runScale(el) {	
	transition(el, {
		styles: {transform: 'scale(0.9)'}
		}, 200, 0).then(() => {
			transition(el, {
				styles: {
				transform: 'scale(1)'
				}
			}, 200, 0)
	})
};	
export function runScaleStyle(el,styles,delay = 0,needLayout=true) {	
	//console.log(el,styles)
	return new Promise((resolve) => {
	transition(el, {styles: styles},100, 0,needLayout).then(()=>{
		resolve()
	})
	})
};

export function timeOut(time) {	
	return new Promise((resolve) => {
		setTimeout(()=>{
			resolve()
		},time)
	})
};

const getJsonTree = function(data,pid){
    let itemArr=[];
    for(let i=0;i<data.length;i++){ 
        let node = data[i];
        if(node.pid==pid ){ 
			let newNode={id:node.id,value:node.id,name:node.nickname,submenu:getJsonTree(data,node.id)};
			itemArr.push(newNode);              
        }
    }
    return itemArr;
} 

export function deptTransform(list,field) {
	if(!list)return [];
	if(Object.prototype.toString.call(list) != '[object Array]'){
		return []
	};
	console.log(getJsonTree(list,0))
	return getJsonTree(list,0)
	
}
export function deptFilterByField(arr,field) { 
  if(!arr)return [];
  console.log(Object.prototype.toString.call(arr))
    if(Object.prototype.toString.call(arr) != '[object Array]'){
		return []
	};
	console.log(arr)
		var map = {};
		var dest = [];
		//var arr = this;
		for(var i = 0; i < arr.length; i++) {
			arr[i].name = arr[i].dept_name[lang]
			arr[i].value = arr[i].org_dept_id
			if(arr[i][field] == -1||arr[i][field] == 0){
				let submenu = [{
					name: arr[i].name, 
					value: arr[i].org_dept_id
					}];
				//let submenu  = []
				arr.forEach(item => {
					    //判断是否有父级
						if(arr[i].org_dept_id == item[field]){
							//console.log(item)
							item.name = item.dept_name[lang]
							item.value = item.org_dept_id
							//item.value = item.org_id
							submenu.push(item)
						}
					})
				
				arr[i].submenu = submenu
				dest.push(arr[i])
			}
		}		
	return dest;
};